<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 100px;
            height: 100px;
            background-color: red;
            position: relative;
            top: 25px;
            left: 25px;
            padding: 10px;
            border: 5px solid pink;
        }
        
        .big {
            height: 200px;
            width: 200px;
            background-color: green;
        }
    </style>
</head>

<body style="margin: 0px;">
    <div class="big">
        <div class="box" style=""></div>
    </div>

</body>
<script>
    var box = document.querySelector('.box');
    console.log(box.offsetParent);
    // box.parentNode 直接返回父级元素，不管父亲有没有定位。
    // box.offsetParent 只返回带有定位的父级元素，如果它们父级都没有定位那么会返回 body
    console.log("left:", box.offsetLeft);
    console.log("top:" + box.offsetTop);
    console.log("width:" + box.offsetWidth);
    console.log("height:" + box.offsetHeight);
    console.log(box.style.marginLeft);
</script>

</html>